package logic

import (
	"bilibili/bilibilirpc/bilibilirpc"
	"bilibili/pkg"
	"context"

	"bilibili/api/internal/svc"
	"bilibili/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RealnameLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRealnameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RealnameLogic {
	return &RealnameLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RealnameLogic) Realname(req *types.RealnameRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	if pkg.Realname(req.Name, req.IdCard) {
		realname, err := l.svcCtx.BilibiliRpc.Realname(l.ctx, &bilibilirpc.RealnameRequest{
			Name:   req.Name,
			IdCard: req.IdCard,
			UserId: req.UserId,
		})
		if err != nil {
			return &types.Response{
				Code:    500,
				Message: "实名认证失败",
				Data:    nil,
			}, nil
		}
		if err != nil {
			return &types.Response{
				Code:    200,
				Message: "实名认证成功",
				Data:    realname,
			}, nil
		}
	}
	return &types.Response{
		Code:    200,
		Message: "实名认证成功",
		Data:    nil,
	}, nil
}
